#!/usr/bin/python
# coding=utf-8
import urllib
import urllib2
import cookielib
import re
import shutil;
import os;
import sys;
import paramiko;

#--------------------------------
#  获得网站的相关信息 仲伟涛
#--------------------------------

iconIp       = '52zuomeng.com';  # icon地址
iconUserName = 'root';  #ssh登录账户 和密码
iconPassWd   = 'meimima';
iconBasePath = '/var/www/allapp/trunk/'#

cj = cookielib.CookieJar()
#POST数据
post_data = urllib.urlencode({'domain': 'www.52zuomeng.com', 'siteorlink': 'site'});
path = 'http://tool.chinaz.com/history/'
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 FirePHP/0.5')]
urllib2.install_opener(opener);
req = urllib2.Request(path, post_data);
html = urllib2.urlopen(req).read();

#拆出收录情况
sCodePat  = re.compile('<div class="detail" align="center">(.*?)</div>', re.S|re.M);
sCodeArr  = sCodePat.findall(html);
sCode = sCodeArr[0];
file_object = open('/tmp/1_shoulu.txt', 'w')
file_object.write(sCode)
file_object.close()
#上传到目录网站中

socks=(iconIp)
transport=paramiko.Transport(socks)
transport.connect(username=iconUserName, password=iconPassWd)
sftp = paramiko.SFTPClient.from_transport(transport)
localpath = '/tmp/1_shoulu.txt';
remotepath = iconBasePath + 'Html/Admin/inc/1_shoulu.txt';
sftp.put(localpath,remotepath)
sftp.close()
transport.close()
print "完成";
